package cn.com.klun.step;

import cn.com.klun.logic.CalculateAveVolMacdLogic;
import cn.com.klun.tjy.base.IStep;
import cn.com.klun.tjy.common.util.DateUtils;
import cn.com.klun.tjy.dao.entity.TblAllStockInfo;
import cn.com.klun.tjy.dao.entity.TblTaskBasicConfig;
import cn.com.klun.tjy.dao.mapper.edit.TblAveVolMacdInfoEditMapper;
import cn.com.klun.tjy.dao.mapper.ser.TblAllStockInfoSerMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CalculateAveVolMacdTask implements IStep<TblAllStockInfo>{

    private static Logger logger = LoggerFactory.getLogger(CalculateAveVolMacdTask.class);

    @Autowired
    private CalculateAveVolMacdLogic calculateAveVolMacdLogic;
    @Autowired
    private TblAllStockInfoSerMapper tblAllStockInfoSerMapper;
    @Autowired
    private TblAveVolMacdInfoEditMapper tblAveVolMacdInfoEditMapper;

    @Override
    public List queryTaskInfo(TblTaskBasicConfig config) {
        TblAllStockInfo tblAllStockInfo = new TblAllStockInfo();
        //数据执行前先更新
        tblAveVolMacdInfoEditMapper.insertInitCode(DateUtils.getCurrDate());
        List<TblAllStockInfo> tblAllStockInfos = tblAllStockInfoSerMapper.queryList(tblAllStockInfo);
        return tblAllStockInfos;
    }

    @Override
    public void runTask(TblAllStockInfo tblAllStockInfo) {
        try {
            logger.info("开始计算股票的信息，stockcode{}",tblAllStockInfo.getStockCode());
            calculateAveVolMacdLogic.exec(tblAllStockInfo);
            logger.info("完成计算股票的信息，stockcode{}",tblAllStockInfo.getStockCode());
        } catch (Exception e) {
            logger.error("处理stockCode【{}】异常，异常信息{}",tblAllStockInfo.getStockCode(),e);
        }
    }

    @Override
    public boolean editTaskInfo(List list) {
        return false;
    }
}
